#include "tool.h"
#include <string.h>

Int  Myhashchars(const char * chars)
{
	Int hashcode=0;
	
	Int length=strlen(chars);

	Int i;

	for(i=0;i<length;i++)
	{
		hashcode=hashcode*31+ ((Int)*(chars+i));
		
	}

	return hashcode;
}



Int FindExists(const linedata *phead,const char *str)
{
	const linedata *pcurt=phead;
	int strhashcode=Myhashchars(str);
	
	while(pcurt!=NULL)
	{

		if(pcurt->hashcode==strhashcode)
		{
			if(strncmp(pcurt->str,str,strlen(str))==0)
			{

				//find the string
				return 1;
			}
		}
		pcurt=pcurt->pNext;

	}


	return 0;

}


void trimchars(char *str)
{


	Int length=strlen(str);
	Int i=length-1;
	char charnum=0;

	while(i>0)
	{
		
		charnum=*(str+i);
		if(charnum=='\n'|charnum=='\r'||charnum==' '||charnum=='\t')
		{
			*(str+i)='\0';
		}
		i--;
	}
	


}
